package bm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import yyee.llee.mmee.pl190.host668.BusKey;
import yyee.llee.mmee.pl190.host668.LiveDataBus;
import com.umeng.commonsdk.statistics.common.MLog;

public class HM extends BroadcastReceiver {

    WifiReceiveListener wifiReceiveListener;

    public interface WifiReceiveListener {

        void wifiOpen();

        void wifiClose();

        void wifiisConnect();

        void mobileisConnect();

        void noNet();
    }

    public void setWifiReceiveListener(WifiReceiveListener wifiReceiveListener) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        this.wifiReceiveListener = wifiReceiveListener;
    }

    String TAG = "HM";

    @Override
    public void onReceive(Context context, Intent intent) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        // wifi打开与否
        if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
            int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
            if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
                MLog.e(TAG, "系统关闭wifi");
                if (wifiReceiveListener != null) {
                    wifiReceiveListener.wifiClose();
                }
            } else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
                MLog.e(TAG, "系统开启wifi");
                if (wifiReceiveListener != null) {
                    wifiReceiveListener.wifiOpen();
                }
            }
        }
        // 监听网络连接，总网络判断，即包括wifi和移动网络的监听
        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
            if (HJ.isNetWorkConnected(context)) {
                if (HJ.isWifiConnected(context)) {
                    MLog.e(TAG, "已连接到wifi网络");
                    if (wifiReceiveListener != null) {
                        wifiReceiveListener.wifiisConnect();
                    }
                    LiveDataBus.get().register(BusKey.NET_STATUS, Integer.class).postValue(IA.MNETSTATUS.WIFI.value);
                }
                if (HJ.isMobileConnected(context)) {
                    MLog.e(TAG, "已连接到移动网络");
                    wifiReceiveListener.mobileisConnect();
                    LiveDataBus.get().register(BusKey.NET_STATUS, Integer.class).postValue(IA.MNETSTATUS.MOBILE.value);
                }
            } else {
                MLog.e(TAG, "已进入无网络次元，请检查网络设置！");
                wifiReceiveListener.noNet();
                LiveDataBus.get().register(BusKey.NET_STATUS, Integer.class).postValue(IA.MNETSTATUS.NO_NET.value);
            }
        }
    }
}
